<?php

use Illuminate\Database\Seeder;
use App\Models\Article_content;
use App\Models\Article;
use Faker\Factory;

class Article_contentTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
//                非模型工厂填充数据
//        Article_content::truncate();
//        $faker = Factory::create('zh_CN');
//        $ids_len = count(Article::select('id')->get()->toArray());
//
//        $data = [];
//        for($i=0;$i<1500;$i++){
//            $data[] = [
//                'articletitle2' => $faker->name,
//                'article_id' => mt_rand(0,$ids_len),
//                'articlecolumn' => $faker->numberBetween(0,5),
//                'articletype' => $faker->numberBetween(0,5),
//                'articlesort' => $faker->numberBetween(0,10),
//                'keywords' => $faker->word(5),
//                'abstract' => $faker->realText(15),
//                'author' => $faker->name,
//                'sources' => $faker->word(5),
//                'allowcomments' =>$faker->numberBetween(0,1),
//                'picture' => $faker->sentence($nbWords = 6, $variableNbWords = true),
//                'content' => $faker->text,
//            ];
//        }
//        Article_content::insert($data);


        //修改关联article_content表外键article_id列数据
        $ids_len = count(Article::select('id')->get()->toArray());
        for($i=0;$i<$ids_len;$i++){
            $data = [
                'article_id' =>mt_rand(0,$ids_len),
            ];
            Article_content::where('id','=',$i)->update($data);
        }


    }

}

